<template>
  <div class="table_continer">
    <div>
      <!-- 列表 ------------------------------------------------------------------------------------------------------->
      <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column prop="equipmentName" label="序号" width="100">
          <template slot-scope="scope">
            <div>{{ scope.$index + 1 }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="supplierNum" label="供应商编号" min-width="150">
          <template slot-scope="scope">
            <el-link @click="handledetailed(scope.row.supplierId)" type="primary">{{ scope.row.supplierNum || '-' }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column prop="supplierName" label="供应商名称" show-overflow-tooltip />
        <el-table-column prop="addr" label="地址" show-overflow-tooltip />
        <el-table-column prop="grade" label="评级">
          <template slot-scope="scope">
            <div>{{ scope.row.grade * 1 + 1 || '-' }} 星</div>
          </template>
        </el-table-column>
        <el-table-column prop="website" label="官网" show-overflow-tooltip>
          <template slot-scope="scope">
            <div>{{ scope.row.website || '-' }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <div :style="'color:' + ['#67C23A', '#F56C6C'][scope.row.status]">
              <i :class="['el-icon-success', 'el-icon-remove'][scope.row.status]" />
              <span>
                {{ ['启用中', '禁用中'][scope.row.status] }}
              </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" show-overflow-tooltip min-width="160">
          <template slot-scope="{row}">
            <div>
              {{ row.remark || '-' }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="创建部门" align="center" min-width="180" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.deptName || '-' }}
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center" min-width="120" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.createBy || '-' }}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="{row}">
            <!-- 此处ID字段特别注意 ------------------------------------------------------------------------------------>
            <el-button v-hasPermi="['supplier_left_update']" type="primary" size="small" icon="el-icon-edit"
              @click="handleEdit(row.supplierId)">编辑
            </el-button>
            <el-button v-hasPermi="['supplier_left_dis']" v-show="row.status == 0" type="danger" icon="el-icon-lock"
              size="small" @click="handleAlter(row.supplierId, row.status)">禁用</el-button>
            <el-button v-hasPermi="['supplier_left_dis']" v-show="row.status == 1" type="success" size="small"
              icon="el-icon-unlock" @click="handleAlter(row.supplierId, row.status)">启用</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- ------------------------------------------------------------------------------------------------------------>
    </div>
    <!-- --------------------------------分页器---------------------------------------------------------- -->
    <div class="table_continer_pagination">
      <el-pagination :current-page="pageParams.pageNum" background :page-sizes="[10, 20, 50, 100]"
        :page-size="pageParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
</template>

<script>
/** 拉取列表远程方法 ---------------------------------------------------------------------------------------------------------- */
import { list, status } from '@/api/purchasing/supplier'
/** ------------------------------------------------------------------------------------------------------------------------- */
import { pageCount } from '@/utils/pagination'
/** 查询参数处理 ---------------------------------------------------------------------------------------------------------- */
function processQueryParams (queryParams, pageParams) {
  const params = Object.assign({}, queryParams, pageParams)
  return params
}
/** ------------------------------------------------------------------------------------------------------------------------- */

export default {
  name: 'PaginationTable',
  data () {
    return {
      pagination: {
        total: 1,
        pageCount: 1
      },
      pageParams: {
        pageNum: 1,
        pageSize: 10,
        /** 列表默认排序字段 ---------------------------------------------------------------------------------------------------------- */
        orderByColumn: 'supplierId',
        /** ------------------------------------------------------------------------------------------------------------------------- */
        isAsc: 'desc'
      },
      queryParams: null,
      tableData: [],
      multipleSelection: []
    }
  },
  mounted () {
    this.refreshList()
  },
  methods: {
    refreshList () {
      const params = processQueryParams(this.queryParams, this.pageParams)
      console.log('查询参数', params);
      // --------consolelog('查询参数', params)
      list(params).then((res) => {
        console.log('获取列表', res);
        // --------consolelog('获取列表', res)
        this.pagination.total = res.total
        this.pagination.pageCount = pageCount(this.pagination.total, this.pageParams.pageSize)
        this.tableData = res.data
      })
    },
    handleQuery (queryParams) {
      this.queryParams = queryParams
      this.refreshList()
    },
    handleSizeChange (value) {
      this.pageParams.pageSize = value
      this.refreshList()
    },
    handleCurrentChange (value) {
      this.pageParams.pageNum = value
      this.refreshList()
    },
    handleSelectionChange (value) {
      // console.log('handleSelectionChange', value)
    },
    // 点击编号跳转基值详情-----------------------------
    handledetailed (id) {
      this.$emit('click_create_reception', id)
    },
    /** 传递点击【编辑】事件 ---------------------------------------------------------------------------------------------------------- */
    handleEdit (id) {
      this.$emit('click_edit', id)
    },
    // 禁用----启用事件------------------------------------------------------------------------------------------------------------------
    handleAlter (supplierId, type) {
      const rule = {
        supplierId,
        status: type == 0 ? 1 : 0
      }
      status(rule).then(() => {
        if (type == 0) {
          this.$message.error('禁用成功');
        } else {
          this.$message.success('启用成功');
        }
        this.refreshList()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.table_continer {
  border-radius: 5px;

  &_pagination {
    background-color: white;
    padding: 10px;
    margin-bottom: 10px;
  }
}
</style>
